package com.atguigu.lease.web.admin.schedule;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author Tsuchi
 * @description TODO
 * @date 2024/12/23 18:29
 */

// 定时任务类
@Component
public class ScheduledTasks {
	@Autowired
	private LeaseAgreementService leaseAgreementService;



	/*
	*   定时检查租约状态 并改为已到期
	* */
	@Scheduled(cron = "0 0 */8 * * *")
	public void checkLeaseStatus(){
		leaseAgreementService.update(new LambdaUpdateWrapper<LeaseAgreement>()
			// 租期小于当前日期
			.le(LeaseAgreement::getLeaseEndDate, new Date())
			// 租约是要在租期内的
			.in(LeaseAgreement::getStatus, 2,5)
			.set(LeaseAgreement::getStatus, LeaseStatus.EXPIRED)
		);

	}
}
